// leaderPerson/pages/pickupLeader/pickupLeader.js
var common = require("../../../common/common.js").common;

Page({
    /**
   * 页面的初始数据
   */
    data: {
        page: 1,
        list: []
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.waitPicker();
        this.getBase();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {
        wx.stopPullDownRefresh();
        this.setData({
            page: 1
        });
        this.waitPicker();
    },
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {
        this.waitPicker();
    },
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    getBase: function() {
        var that = this;
        common.request({
            endpoint: "set/app_base",
            method: "get",
            data: {},
            success: res => {
                wx.setNavigationBarTitle({
                    title: res.extra.leader_title ? res.extra.leader_title + "收货" : "团长" + "收货"
                });
                that.setData({
                    color_main: res.extra.color_main,
                    time_choose: res.extra.time_choose,
                    apptitle: res.extra.title,
                    leader_share: res.extra.leader_share,
                    user_share: res.extra.user_share,
                    leaderName: res.extra.leader_title ? res.extra.leader_title : "团长",
                    if_leadersales_show: res.extra.if_leadersales_show,
                    leader_detail_edit: res.extra.leader_detail_edit,
                    phone: res.extra.phone
                });
            }
        });
    },
    waitPicker: function() {
        let _this = this;
        common.request({
            endpoint: "My/waitpick/leader_wait3",
            method: "post",
            data: {
                openid: wx.getStorageSync("user").openid,
                page: _this.data.page
            },
            header: {
                "content-type": "application/json"
            },
            success: res => {
                var list = res.extra;
                list = _this.data.page == 1 ? list : _this.data.list.concat(list);
                _this.setData({
                    list: list,
                    page: _this.data.page + 1
                });
            },
            fail(res) {}
        });
    }
});